<%@ page import="br.unicarioca.viaexpositus.Permissao" %>

<%  def menuMap %>

<g:isLoggedIn>
<%
    if(session.usuario){
        def role = "%${session.usuarioAcegi.getAuthorities()[0]}%"
        def urls = Permissao.findAll("from Permissao p where p.perfil like :role",[role:role]).url
        def acoes = []

        urls.each{ url ->
           acoes << url.split("/").findAll{it}
        }

        acoes = acoes.findAll{it[1] == "list"}

        def controllersMenu = []
        acoes.each{
            controllersMenu << it[0]
        }

        menuMap = []
        controllersMenu.each{ controller ->
            menuMap << [controller:controller, action:"list", label:message(code:'menu.'+controller)]
        }%>
      <%
    }

%>
</g:isLoggedIn>
<ul>
    <g:isNotLoggedIn>
        <li><a href="/via" title="Link para Principal">Principal</a></li>
    </g:isNotLoggedIn>
    <g:isLoggedIn>
      <li><a href="${createLink(controller:'inicial', action:'index')}" title="Link para Principal">Principal</a></li>
      <g:each in="${menuMap}" var="menuItem">
          <li><a href="${menuItem.url?:createLink(controller:menuItem.controller, action:menuItem.action)}" title="Link para ${menuItem.label}">${menuItem.label}</a></li>
      </g:each>
    </g:isLoggedIn>
</ul>